<template>
	<popup v-model="currentValue">
		<view class="share_popup">
			<view class="share_popup_close" @click="currentValue = false">取消</view>
			<view class="share_popup_content">
				<!-- #ifdef MP -->
				<button class="share_popup_button" open-type="share">
					<image class="share_popup_button_icon" src="../../static/icon/ic_pic.png" mode="aspectFit"></image>
					<text class="share_popup_button_text">发给好友</text>
				</button>
				<!-- #endif -->
				<!-- #ifdef APP-PLUS -->
				<button class="share_popup_button" @click="onAppShare">
					<image class="share_popup_button_icon" src="../../static/icon/ic_pic.png" mode="aspectFit"></image>
					<text class="share_popup_button_text">发给好友</text>
				</button>
				<!-- #endif -->
				<button class="share_popup_button onSave" @click="onPageJump">
					<image class="share_popup_button_icon" src="../../static/icon/ic_share_pictures.png" mode="aspectFit"></image>
					<text class="share_popup_button_text">保存海报</text>
				</button>
			</view>
		</view>
	</popup>
</template>

<script>
import Popup from '@/components/common/popup.vue';
import { mapState, mapMutations } from 'vuex';
export default {
	components: {
		Popup
	},
	props: {
		value: {
			type: Boolean,
			default: false
		},
		data: {
			type: Object,
			default: {}
		}
	},
	data() {
		return {
			currentValue: false,
			shareData: {}
		};
	},
	computed: {
		...mapState(["userInfo"])
	},
	created() {
		if (typeof this.value !== 'undefined') {
			this.currentValue = this.value;
		}
		if (this.data) {
			this.shareData = this.data;
		}
	},
	watch: {
		value(val) {
			this.currentValue = val;
		},
		currentValue(val) {
			this.$emit(val ? 'on-show' : 'on-hide');
			this.$emit('input', val);
		},
		data(val){
			this.shareData = val;
		}
	},
	//方法
	methods: {
		show(data){
			this.currentValue = true;
			this.shareData = data;
		},
		onPageJump() {
			this.currentValue = false;
			uni.navigateTo({
				url: "/pagesMy/my/distribution/scanCode?pure=1"
			});
		},
		onAppShare() {
			// uni.share({
			// 	provider: 'weixin',
			// 	scene: 'WXSceneSession',
			// 	type: 0,
			// 	title: this.dataInfo.share.shareTitle,
			// 	href: this.dataInfo.share.shareUrl,
			// 	summary: this.dataInfo.share.shareContent,
			// 	imageUrl: this.dataInfo.share.shareImg,
			// 	success: function(res) {
			// 		console.log('success:' + JSON.stringify(res));
			// 	},
			// 	fail: function(err) {
			// 		console.log('fail:' + JSON.stringify(err));
			// 	}
			// });
		}
	},
	//用户点击分享
	onShareAppMessage(e) {
		let shareData = this.shareData;
		if(this.userInfo.token){
			shareData.path += "&recommendCode=" + this.userInfo.uid;
		}
		return shareData;
	}
};
</script>
<style lang="scss" scoped>
@import '@/style/mixin.scss';
.share_popup {
	background-color: #ffffff;
	border-radius: 20rpx 20rpx 0rpx 0rpx;
	height: 360rpx;
	width: 100%;
	position: relative;
}
.share_popup_close {
	position: absolute;
	top: 32rpx;
	right: 32rpx;
	font-size: 28rpx;
	color: #333435;
	z-index: 3;
}
.share_popup_content {
	height: 100%;
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: row;
	justify-content: space-around;
	align-items: center;
}
.share_popup_button {
	/* #ifndef APP-NVUE */
	display: flex;
	/* #endif */
	flex-direction: column;
	align-items: center;
	width: 200rpx;
	line-height: initial;
}
.share_popup_button_icon {
	width: 120rpx;
	height: 120rpx;
}
.share_popup_button_text {
	font-size: 28rpx;
	color: #333435;
	margin-top: 23rpx;
	line-height: 28rpx;
	text-align: center;
}
</style>
